<!-- file config -->
<script> 
	
	$(function(){
		/* REMOVE DUPLICATE ID */
		var ids = [];
		$('*').each(function() {
		    if (this.id && this.id !== '') {
		        if (ids[this.id]) {
		            $(this).remove();
		        } else {
		            ids[this.id] = this
		        }
		    }
		});
		
		/* external function */
		
        function format(state) {
			tambahan = "";
			if (typeof $(state.element[0]).attr("alt") != "undefined")
				tambahan = $(state.element[0]).attr("alt");
            return state.text+tambahan ; 
        }
		
		$.fn.getCombobox = function(data, key, label, desc){
			var field = $(this);
			field.html("<option></option>");
			$.ajax({
				url : "c_public_function",
				data : data,
				type : 'POST', dataType : 'json'
			}).done(function(response){
				for(i=0;i<response.length;i++){
					var option = "<option value='"+response[i][key]+"' ";
					if (desc != "")
						option += " alt='<div class=desc>"+response[i][desc]+"</div>'";
						
					option += " >"+response[i][label]+"</option>";
					field.append(option);
				}
				
				field.select2({
					placeholder: "-",
					allowClear: true,
					formatResult: format,
					formatSelection: format,
					escapeMarkup: function (m) {
						return m;
					}
				});
			});
		}
		
		$.fn.serializeObject = function()
		{
		   var o = {};
		   var a = this.serializeArray();
		   $.each(a, function() {
			   if (o[this.name]) {
				   if (!o[this.name].push) {
					   o[this.name] = [o[this.name]];
				   }
				   o[this.name].push(this.value || '');
			   } else {
				   o[this.name] = this.value || '';
			   }
		   });
		   return o;
		};
		
		/* declarisasi */
		
		task_config = $("#task-config");
		btnadd_config = $("#btn-add-config");
		btncancel_config =  $("#btn-cancel-config");
		btnsave_config = $("#btn-save-config");
		form_config = $("#form-config");
		
		field_config_id = $("#config_id");
		field_config_dashboard = $("#config_dashboard");
		field_config_refresh = $("#config_refresh");
		field_config_suara = $("#config_suara");
		
		/* function */
		
		/* method started */
		
		/* make component */
		CKEDITOR.replace( 'config_dashboard' );
		/* maybe you need * /
		
		field_task_assign_date.datepicker({ dateFormat : 'dd-MM-yy'});
		field_status.select2({
					placeholder: "-",
					allowClear: true,
					formatResult: format,
					formatSelection: format,
					escapeMarkup: function (m) {
						return m;
					}
				});
		m_staff_id.select2("val",dataRow.m_staff_id);
				
		/*                  */
		
	
		
		/* event */
		
		
		btnsave_config.click(function(){
			data = form_config.serializeObject();
            data.config_dashboard = CKEDITOR.instances.config_dashboard.getData();
			$.ajax({
				url : "c_config",
				data : data,
				type : 'POST'
			}).done(function(response){
			});
		});
	});
    
</script>
	<div class="portlet box blue"  tabindex="-1" >
	   <div class="portlet-title">
		  <div class="caption"><i class="icon-reorder"></i>Form config</div>
		  <div class="tools">
			 <a href="javascript:;" class="collapse"></a>
		  </div>
	   </div>

		<div class="portlet-body form">
		<!-- BEGIN FORM-->
		<form action="#" id="form-config" class="horizontal-form" onSubmit="javascript:return false;">

		<input type="hidden" value="UPDATE" name="task" id="task-config">
		<input id="config_id" name="config_id" hidden=hidden value="1" />

			 <div class="form-body">
				<h3 class="form-section">config</h3>

				<div class="row"><div class="col-md-12"><div class="form-group"><label class="control-label">Template Dashboard:</label><textarea class="ckeditor form-control" name="config_dashboard" id="config_dashboard" ><?php echo @$config_dashboard; ?></textarea> </div></div></div>
				
                 
				<!-- div class="row"><div class="col-md-6"><div class="form-group"><label class="control-label">Refresh:</label><input id="config_refresh" name="config_refresh" class="form-control" /></div></div></div -->
				<div class="row"><div class="col-md-6"><div class="form-group"><label class="control-label">Template Suara:</label><input id="config_suara" name="config_suara" class="form-control" value="<?php echo @$config_suara; ?>" /></div></div></div>
		
			 </div>
			 <div class="form-actions right">
				<button type="submit" id="btn-save-config" class="btn blue"><i class="icon-ok"></i> Save</button>
			 </div>
		  </form>
		  <!-- END FORM--> 
	   </div>
	</div>

